package org.feng.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author 冯帅
 * @des TODO
 * @date 2021/8/26 10:37
 * @email 15612509687@163.com
 */
public class HttpUtil {
    public static HttpServletRequest getRequest() {
        HttpServletRequest request = null;
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        if (attributes != null) {
            ServletRequestAttributes requestAttributes = (ServletRequestAttributes) attributes;
            request = requestAttributes.getRequest();
        }
        return request;

    }

    public static HttpServletResponse getResponse() {
        HttpServletResponse response = null;
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        if (attributes != null) {
            ServletRequestAttributes requestAttributes = (ServletRequestAttributes) attributes;
            response = requestAttributes.getResponse();
        }
        return response;

    }
}
